package dkbta.ontology.elements.abstractions.interpolation;

import java.util.Map;

import dkbta.util.time.TimeInterval;

/**
 * A persistence function used to interpolate time intervals with values
 * 
 * @author Uri Kanonov
 */
public class PersistenceFunction{
	/** Persistence tables per value */
	private final Map<Object, PersistenceTable> _persistenceTables;

	/**
	 * Initializes a persistence function with persistence tables per value
	 * 
	 * @param persistenceTables Persistence tables per value
	 */
	public PersistenceFunction(Map<Object, PersistenceTable> persistenceTables){
		_persistenceTables = persistenceTables;
	}

	/**
	 * Checks whether the two time intervals that share the given value can be joined
	 * 
	 * @param value The value
	 * @param before The first interval
	 * @param after The second interval
	 * @return Whether the two time intervals can be joined
	 */
	public boolean canBeJoined(Object value, TimeInterval before, TimeInterval after){
		return _persistenceTables.get(value).canBeJoined(before, after);
	}

	@Override
	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("Persistence Function: ");
		for (Map.Entry<Object, PersistenceTable> e : _persistenceTables.entrySet()){
			sb.append("\r\n\tValue:").append(e.getKey());
			sb.append(e.getValue());
		}
		return sb.toString();
	}
}
